
import java.awt.Cursor;
import javax.swing.JOptionPane;

public class frm_ordem_de_servico extends javax.swing.JFrame {

    public static String nivel_acesso;
    public frm_ordem_de_servico(String nivel_acesso) {
        this.nivel_acesso = nivel_acesso;
        initComponents();
        jp_em_aberto.setVisible(false);
        try {
            javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
            javax.swing.SwingUtilities.updateComponentTreeUI(this);
        } catch (Exception e) {
            e.printStackTrace();
        }
        btn_salvar.setEnabled(false);
        setExtendedState(MAXIMIZED_BOTH);
        nomeBotoes();
        maoBotoes();
        PacienteController pacienteController = new PacienteController();
        OSController osController = new OSController();
        pacienteController.listarPacientesCombo();
        osController.listarTipoServicoCombo();
        osController.listarOSCombo();
        calcularTotal();
        verificarNivelAcesso();
    }
    
    //<editor-fold defaultstate="collapsed" desc="Atributos">
    int id_os;
    int id_paciente;
    int cod_os;
    String nome_paciente;
    String tipo_servico;
    String servico;
    int quantidade;
    String data_entrada;
    String data_entrega;
    String valor_unitario;
    String valor_total;
    String situacao_servico;
    String situacao_pagamento;
    String obs;
    
    String valor_parcela;
    String vencimento_parcela;
    int qtd_parcelas;
    String situacao = "ABERTO";
    
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Métodos">
    
    
    public void habilitarCampos(){
        tf_codigo.setEditable(true);
        tf_data_entrada.setEditable(true);
        tf_data_entrega.setEditable(true);
        tf_obs.setEditable(true);
    }
    
    public void desabilitarCampos(){
        tf_codigo.setEditable(false);
        tf_data_entrada.setEditable(false);
        tf_data_entrega.setEditable(false);
        tf_obs.setEditable(false);
    }
    
    public void limparCampos() {
        tf_codigo.setText("");
        tf_data_entrada.setText("");
        tf_data_entrega.setText("");
        cb_paciente.setSelectedIndex(0);
        //cb_tipo_servico.setSelectedIndex(0);
        //cb_servico.setSelectedIndex(0);
        cb_quantidade.setSelectedIndex(0);
        tf_valor_unitario.setText("");
        tf_valor_total.setText("");
        cb_situacao.setSelectedIndex(0);
        cb_pagamento.setSelectedIndex(0);
        tf_obs.setText("");
        cb_qtd_parcelas.setSelectedIndex(0);
        tf_valor_parcela.setText("");
        tf_vencimento_parcela.setText("");
    }

    public void incrementarCodigo() {
        OSDAO osDAO = new OSDAO();
        tf_codigo.setText(osDAO.buscar_ProximoID("cod_os")+"");
    }

    /*
     * Método para validar se campos obrigatorios para o cadastro estao
     * corretamente preenchidos.
     */
    public boolean validarFormulario() {
        
         if(data_entrada.equals("")||data_entrega.equals("")
             ||cb_paciente.getSelectedItem().equals("Selecione um paciente")
                 || cb_pagamento.getSelectedItem().equals("Selecione")){
             
             return false; 
         }
        else{
            return true;
        }
    }

    /*
     * Método que busca a qtd de linhas e colunas para limpar a tabela os.
     */
    public void limparTabelaOS() {
        int linha = jt_os.getRowCount();
        int coluna = jt_os.getColumnCount();
        for (int i = 0; i < linha; i++) {
            for (int j = 0; j < coluna; j++) {
                jt_os.setValueAt("", i, j);
            }
        }
    }

    public void nomeBotoes() {
        btn_novo.setToolTipText("Novo cadastro");
        btn_salvar.setToolTipText("Salvar");
        btn_excluir.setToolTipText("Excluir");
        btn_editar.setToolTipText("Editar");
        btn_alterar.setToolTipText("Alterar");
    }

    public void maoBotoes() {
        btn_novo.setCursor(new Cursor(Cursor.HAND_CURSOR));
        btn_salvar.setCursor(new Cursor(Cursor.HAND_CURSOR));
        btn_excluir.setCursor(new Cursor(Cursor.HAND_CURSOR));
        btn_editar.setCursor(new Cursor(Cursor.HAND_CURSOR));
        btn_alterar.setCursor(new Cursor(Cursor.HAND_CURSOR));
    }
    //</editor-fold>

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jp_dados_da_os = new javax.swing.JPanel();
        lbl_codigo = new javax.swing.JLabel();
        tf_codigo = new javax.swing.JTextField();
        lbl_tipo_servico = new javax.swing.JLabel();
        lbl_dentista = new javax.swing.JLabel();
        cb_paciente = new javax.swing.JComboBox();
        cb_tipo_servico = new javax.swing.JComboBox();
        lbl_servico = new javax.swing.JLabel();
        cb_servico = new javax.swing.JComboBox();
        lbl_qtd = new javax.swing.JLabel();
        cb_quantidade = new javax.swing.JComboBox();
        lbl_valor_unitario = new javax.swing.JLabel();
        lbl_valor_total = new javax.swing.JLabel();
        lbl_data_entrada = new javax.swing.JLabel();
        tf_data_entrada = new javax.swing.JFormattedTextField();
        lbl_pagamento = new javax.swing.JLabel();
        cb_pagamento = new javax.swing.JComboBox();
        lbl_data_entrega = new javax.swing.JLabel();
        tf_data_entrega = new javax.swing.JFormattedTextField();
        lbl_obs = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tf_obs = new javax.swing.JTextArea();
        lbl_situacao_servico = new javax.swing.JLabel();
        cb_situacao = new javax.swing.JComboBox();
        tf_valor_unitario = new javax.swing.JTextField();
        tf_valor_total = new javax.swing.JTextField();
        jp_pesquisa = new javax.swing.JPanel();
        lbl_filtrar = new javax.swing.JLabel();
        cb_filtrar = new javax.swing.JComboBox();
        lbl_igual = new javax.swing.JLabel();
        tf_pesquisar = new javax.swing.JTextField();
        btn_pesquisar = new javax.swing.JButton();
        jp_paciente = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jt_os = new javax.swing.JTable();
        jp_menu = new javax.swing.JPanel();
        btn_novo = new javax.swing.JButton();
        btn_excluir = new javax.swing.JButton();
        btn_salvar = new javax.swing.JButton();
        btn_alterar = new javax.swing.JButton();
        btn_editar = new javax.swing.JButton();
        jp_em_aberto = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        cb_qtd_parcelas = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        tf_vencimento_parcela = new javax.swing.JFormattedTextField();
        jLabel12 = new javax.swing.JLabel();
        tf_valor_parcela = new javax.swing.JFormattedTextField();
        jPanel1 = new javax.swing.JPanel();
        lbl_dentista1 = new javax.swing.JLabel();
        cb_paciente_consulta = new javax.swing.JComboBox();
        jScrollPane3 = new javax.swing.JScrollPane();
        jt_parcelas = new javax.swing.JTable();
        jm_menu = new javax.swing.JMenuBar();
        jm_menu_opcoes = new javax.swing.JMenu();
        jm_menu_backup = new javax.swing.JMenuItem();
        jm_menu_restaurar_backup = new javax.swing.JMenuItem();
        jm_menu_usuarios = new javax.swing.JMenuItem();
        jm_menu_sair = new javax.swing.JMenuItem();
        jm_menu_gerenciar = new javax.swing.JMenu();
        jm_menu_clinicas = new javax.swing.JMenuItem();
        jm_menu_dentistas = new javax.swing.JMenuItem();
        jm_menu_pacientes = new javax.swing.JMenuItem();
        jm_menu_ordem_de_servico = new javax.swing.JMenuItem();
        jm_menu_ajuda = new javax.swing.JMenu();
        jm_menu_conteudo_ajuda = new javax.swing.JMenuItem();
        jm_menu_sobre = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Clínica de Próteses | Ordem de Serviço");

        jp_dados_da_os.setBackground(new java.awt.Color(255, 255, 255));
        jp_dados_da_os.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados da OS:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 18), new java.awt.Color(0, 102, 153))); // NOI18N
        jp_dados_da_os.setForeground(new java.awt.Color(255, 255, 255));

        lbl_codigo.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_codigo.setText("Código OS:");

        tf_codigo.setEditable(false);
        tf_codigo.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        lbl_tipo_servico.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_tipo_servico.setText("T. Serviço:*");

        lbl_dentista.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_dentista.setText("Paciente:*");

        cb_paciente.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        cb_paciente.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione um paciente" }));

        cb_tipo_servico.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        cb_tipo_servico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_tipo_servicoActionPerformed(evt);
            }
        });

        lbl_servico.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_servico.setText("Serviço:*");

        cb_servico.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        cb_servico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_servicoActionPerformed(evt);
            }
        });

        lbl_qtd.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_qtd.setText("Quantidade:");

        cb_quantidade.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        cb_quantidade.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" }));
        cb_quantidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_quantidadeActionPerformed(evt);
            }
        });

        lbl_valor_unitario.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_valor_unitario.setText("Unit:");

        lbl_valor_total.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_valor_total.setText("Total:");

        lbl_data_entrada.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_data_entrada.setText("Entrada:*");

        tf_data_entrada.setEditable(false);
        try {
            tf_data_entrada.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##-##-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        tf_data_entrada.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        lbl_pagamento.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_pagamento.setText("Pagamento:*");

        cb_pagamento.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        cb_pagamento.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione", "Em aberto", "Pago" }));
        cb_pagamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_pagamentoActionPerformed(evt);
            }
        });

        lbl_data_entrega.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_data_entrega.setText("Entrega:*");

        tf_data_entrega.setEditable(false);
        try {
            tf_data_entrega.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##-##-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        tf_data_entrega.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        lbl_obs.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_obs.setText("Observação:");

        tf_obs.setColumns(20);
        tf_obs.setEditable(false);
        tf_obs.setRows(5);
        jScrollPane2.setViewportView(tf_obs);

        lbl_situacao_servico.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_situacao_servico.setText("Situação:");

        cb_situacao.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        cb_situacao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Em construção", "Concluído" }));

        tf_valor_unitario.setEditable(false);
        tf_valor_unitario.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        tf_valor_total.setEditable(false);
        tf_valor_total.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        javax.swing.GroupLayout jp_dados_da_osLayout = new javax.swing.GroupLayout(jp_dados_da_os);
        jp_dados_da_os.setLayout(jp_dados_da_osLayout);
        jp_dados_da_osLayout.setHorizontalGroup(
            jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_dados_da_osLayout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbl_servico)
                    .addComponent(lbl_tipo_servico)
                    .addComponent(lbl_dentista))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tf_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jp_dados_da_osLayout.createSequentialGroup()
                        .addComponent(tf_data_entrada, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbl_data_entrega)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_data_entrega, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(cb_paciente, javax.swing.GroupLayout.PREFERRED_SIZE, 368, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cb_tipo_servico, javax.swing.GroupLayout.PREFERRED_SIZE, 368, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cb_servico, javax.swing.GroupLayout.PREFERRED_SIZE, 368, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10))
            .addGroup(jp_dados_da_osLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbl_qtd)
                    .addComponent(lbl_situacao_servico)
                    .addComponent(lbl_pagamento))
                .addGap(18, 18, 18)
                .addGroup(jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(cb_pagamento, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(cb_situacao, javax.swing.GroupLayout.Alignment.LEADING, 0, 118, Short.MAX_VALUE))
                    .addGroup(jp_dados_da_osLayout.createSequentialGroup()
                        .addComponent(cb_quantidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(14, 14, 14)
                        .addComponent(lbl_valor_unitario)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_valor_unitario, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jp_dados_da_osLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(lbl_obs)
                        .addGap(141, 141, 141))
                    .addGroup(jp_dados_da_osLayout.createSequentialGroup()
                        .addComponent(lbl_valor_total)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tf_valor_total, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))))
            .addGroup(jp_dados_da_osLayout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbl_data_entrada)
                    .addComponent(lbl_codigo))
                .addContainerGap())
        );
        jp_dados_da_osLayout.setVerticalGroup(
            jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_dados_da_osLayout.createSequentialGroup()
                .addGroup(jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_codigo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(lbl_data_entrada)
                    .addComponent(tf_data_entrada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_data_entrega)
                    .addComponent(tf_data_entrega, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_obs))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jp_dados_da_osLayout.createSequentialGroup()
                        .addGroup(jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lbl_dentista)
                            .addComponent(cb_paciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbl_tipo_servico)
                            .addComponent(cb_tipo_servico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lbl_servico)
                            .addComponent(cb_servico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(4, 4, 4)
                .addGroup(jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_qtd)
                    .addComponent(cb_quantidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_valor_unitario)
                    .addComponent(tf_valor_unitario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_valor_total)
                    .addComponent(tf_valor_total, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lbl_situacao_servico)
                    .addComponent(cb_situacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jp_dados_da_osLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(lbl_pagamento)
                    .addComponent(cb_pagamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        jp_dados_da_osLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {cb_paciente, cb_tipo_servico});

        jp_pesquisa.setBackground(new java.awt.Color(255, 255, 255));
        jp_pesquisa.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Pesquisa:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 18), new java.awt.Color(0, 102, 153))); // NOI18N

        lbl_filtrar.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_filtrar.setText("Filtrar por:");

        cb_filtrar.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        cb_filtrar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Todos", "Código", "Paciente" }));

        lbl_igual.setText("=");

        tf_pesquisar.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        btn_pesquisar.setText("Pesquisar");
        btn_pesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_pesquisarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jp_pesquisaLayout = new javax.swing.GroupLayout(jp_pesquisa);
        jp_pesquisa.setLayout(jp_pesquisaLayout);
        jp_pesquisaLayout.setHorizontalGroup(
            jp_pesquisaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_pesquisaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbl_filtrar)
                .addGap(18, 18, 18)
                .addComponent(cb_filtrar, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbl_igual)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tf_pesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_pesquisar)
                .addContainerGap())
        );
        jp_pesquisaLayout.setVerticalGroup(
            jp_pesquisaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_pesquisaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jp_pesquisaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_filtrar)
                    .addComponent(cb_filtrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_igual)
                    .addComponent(tf_pesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_pesquisar))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        jp_paciente.setBackground(new java.awt.Color(255, 255, 255));
        jp_paciente.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "OS:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 18), new java.awt.Color(0, 102, 153))); // NOI18N

        jt_os.setAutoCreateRowSorter(true);
        jt_os.setFont(new java.awt.Font("Calibri", 0, 10)); // NOI18N
        jt_os.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Cód", "Cód OS", "Paciente", "Tipo Serviço", "Serviço", "Quantidade", "Entrada", "Entrega", "Valor Unitario", "Valor Total", "Situação Serviço", "Situação Pagamento", "Obs"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jt_os.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jScrollPane1.setViewportView(jt_os);

        javax.swing.GroupLayout jp_pacienteLayout = new javax.swing.GroupLayout(jp_paciente);
        jp_paciente.setLayout(jp_pacienteLayout);
        jp_pacienteLayout.setHorizontalGroup(
            jp_pacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_pacienteLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
        );
        jp_pacienteLayout.setVerticalGroup(
            jp_pacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_pacienteLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jp_menu.setBackground(new java.awt.Color(255, 255, 255));
        jp_menu.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        btn_novo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/img_novo.png"))); // NOI18N
        btn_novo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_novoActionPerformed(evt);
            }
        });

        btn_excluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/img_excluir.png"))); // NOI18N
        btn_excluir.setMaximumSize(new java.awt.Dimension(65, 41));
        btn_excluir.setMinimumSize(new java.awt.Dimension(65, 41));
        btn_excluir.setPreferredSize(new java.awt.Dimension(65, 41));

        btn_salvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/img_salvar.png"))); // NOI18N
        btn_salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_salvarActionPerformed(evt);
            }
        });

        btn_alterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/img_alterar.png"))); // NOI18N
        btn_alterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_alterarActionPerformed(evt);
            }
        });

        btn_editar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/img_editar.png"))); // NOI18N
        btn_editar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_editarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jp_menuLayout = new javax.swing.GroupLayout(jp_menu);
        jp_menu.setLayout(jp_menuLayout);
        jp_menuLayout.setHorizontalGroup(
            jp_menuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_menuLayout.createSequentialGroup()
                .addComponent(btn_novo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_salvar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_excluir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_editar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_alterar)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jp_menuLayout.setVerticalGroup(
            jp_menuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_menuLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jp_menuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(btn_novo)
                    .addComponent(btn_salvar)
                    .addComponent(btn_excluir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_editar)
                    .addComponent(btn_alterar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jp_em_aberto.setBackground(new java.awt.Color(255, 255, 255));
        jp_em_aberto.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados do parcelamento:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 18), new java.awt.Color(0, 102, 153))); // NOI18N

        jLabel10.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        jLabel10.setText("Parcela:*");

        cb_qtd_parcelas.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        cb_qtd_parcelas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }));
        cb_qtd_parcelas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_qtd_parcelasActionPerformed(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        jLabel11.setText("Vencimento:*");

        try {
            tf_vencimento_parcela.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##-##-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        tf_vencimento_parcela.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        jLabel12.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        jLabel12.setText("Valor:*");

        tf_valor_parcela.setEnabled(false);
        tf_valor_parcela.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        javax.swing.GroupLayout jp_em_abertoLayout = new javax.swing.GroupLayout(jp_em_aberto);
        jp_em_aberto.setLayout(jp_em_abertoLayout);
        jp_em_abertoLayout.setHorizontalGroup(
            jp_em_abertoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_em_abertoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel10)
                .addGap(18, 18, 18)
                .addComponent(cb_qtd_parcelas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(50, 50, 50)
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tf_valor_parcela, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tf_vencimento_parcela, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jp_em_abertoLayout.setVerticalGroup(
            jp_em_abertoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_em_abertoLayout.createSequentialGroup()
                .addGroup(jp_em_abertoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf_vencimento_parcela, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(jp_em_abertoLayout.createSequentialGroup()
                .addGroup(jp_em_abertoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(cb_qtd_parcelas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(tf_valor_parcela, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12))
                .addGap(121, 121, 121))
        );

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Parcelas:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 18), new java.awt.Color(0, 102, 153))); // NOI18N

        lbl_dentista1.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_dentista1.setText("OS:");

        cb_paciente_consulta.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        cb_paciente_consulta.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione a OS" }));
        cb_paciente_consulta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_paciente_consultaActionPerformed(evt);
            }
        });

        jt_parcelas.setAutoCreateRowSorter(true);
        jt_parcelas.setFont(new java.awt.Font("Calibri", 0, 10)); // NOI18N
        jt_parcelas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Parcela", "Valor da Parcela", "Vencimento", "Situação"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jt_parcelas.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jScrollPane3.setViewportView(jt_parcelas);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lbl_dentista1)
                        .addGap(18, 18, 18)
                        .addComponent(cb_paciente_consulta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 721, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_dentista1)
                    .addComponent(cb_paciente_consulta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
                .addContainerGap())
        );

        jm_menu_opcoes.setText("Opções");
        jm_menu_opcoes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jm_menu_opcoesActionPerformed(evt);
            }
        });

        jm_menu_backup.setText("Backup");
        jm_menu_backup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jm_menu_backupActionPerformed(evt);
            }
        });
        jm_menu_opcoes.add(jm_menu_backup);

        jm_menu_restaurar_backup.setText("Restaurar backup");
        jm_menu_restaurar_backup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jm_menu_restaurar_backupActionPerformed(evt);
            }
        });
        jm_menu_opcoes.add(jm_menu_restaurar_backup);

        jm_menu_usuarios.setText("Gerenciar usuários");
        jm_menu_opcoes.add(jm_menu_usuarios);

        jm_menu_sair.setText("Sair");
        jm_menu_sair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jm_menu_sairActionPerformed(evt);
            }
        });
        jm_menu_opcoes.add(jm_menu_sair);

        jm_menu.add(jm_menu_opcoes);

        jm_menu_gerenciar.setText("Gerenciar");

        jm_menu_clinicas.setText("Clinicas");
        jm_menu_clinicas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jm_menu_clinicasActionPerformed(evt);
            }
        });
        jm_menu_gerenciar.add(jm_menu_clinicas);

        jm_menu_dentistas.setText("Dentistas");
        jm_menu_dentistas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jm_menu_dentistasActionPerformed(evt);
            }
        });
        jm_menu_gerenciar.add(jm_menu_dentistas);

        jm_menu_pacientes.setText("Pacientes");
        jm_menu_pacientes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jm_menu_pacientesActionPerformed(evt);
            }
        });
        jm_menu_gerenciar.add(jm_menu_pacientes);

        jm_menu_ordem_de_servico.setText("Ordem de Serviço");
        jm_menu_ordem_de_servico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jm_menu_ordem_de_servicoActionPerformed(evt);
            }
        });
        jm_menu_gerenciar.add(jm_menu_ordem_de_servico);

        jm_menu.add(jm_menu_gerenciar);

        jm_menu_ajuda.setText("Ajuda");

        jm_menu_conteudo_ajuda.setText("Conteúdo da ajuda");
        jm_menu_ajuda.add(jm_menu_conteudo_ajuda);

        jm_menu_sobre.setText("Sobre");
        jm_menu_ajuda.add(jm_menu_sobre);

        jm_menu.add(jm_menu_ajuda);

        setJMenuBar(jm_menu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jp_dados_da_os, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jp_em_aberto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jp_paciente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jp_pesquisa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(jp_menu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jp_menu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jp_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jp_paciente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jp_dados_da_os, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jp_em_aberto, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 9, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    public void verificarNivelAcesso(){
        if(nivel_acesso.equals("Operador")){
            jm_menu_usuarios.setEnabled(false);
            jm_menu_usuarios.setVisible(false);       
        }
        else{
            jm_menu_usuarios.setEnabled(true);
            jm_menu_usuarios.setVisible(true);
        }
    }
    
    public String inverterData(String data){
        String dia = data.substring(0, 2);
        String mes = data.substring(3, 5);
        String ano = data.substring(6, 10);
        data = ano + "-" + mes + "-" + dia;
        return data;
    }
    
    private void cb_pagamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_pagamentoActionPerformed
        if (cb_pagamento.getSelectedItem().equals("Em aberto")) {
            jp_em_aberto.setVisible(true);
        } else {
            jp_em_aberto.setVisible(false);
        }
    }//GEN-LAST:event_cb_pagamentoActionPerformed

    private void btn_editarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_editarActionPerformed
        btn_salvar.setEnabled(false);
        habilitarCampos();
        OSController osController = new OSController();
        int linha = jt_os.getSelectedRow();
        int id_os = osController.buscarIDdeTabelas(linha, 0);
        //try{
        osController.editarOS(id_os);
        //}catch(Exception e){JOptionPane.showMessageDialog(this,"Selecione um registro.");}
    }//GEN-LAST:event_btn_editarActionPerformed

    private void btn_alterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_alterarActionPerformed
        OSController osController = new OSController();
        int linha = jt_os.getSelectedRow();
        id_os = osController.buscarIDdeTabelas(linha, 0);
        cod_os = Integer.parseInt(tf_codigo.getText());
        nome_paciente = cb_paciente.getSelectedItem() + "";//busca o nome da clinica que esta no cb_clinica.
        id_paciente = osController.buscarIDPaciente(nome_paciente);//busca o id_clinica a partir do nome selecionado no cb_clinica.
        tipo_servico = cb_tipo_servico.getSelectedItem() + "";
        servico = cb_servico.getSelectedItem() + "";
        quantidade = Integer.parseInt(cb_quantidade.getSelectedItem() + "");
        data_entrada = inverterData(tf_data_entrada.getText()+"");
        data_entrega = inverterData(tf_data_entrega.getText()+"");
        
        valor_unitario = tf_valor_unitario.getText();
        valor_total = tf_valor_total.getText();
        situacao_servico = cb_situacao.getSelectedItem() + "";
        situacao_pagamento = cb_pagamento.getSelectedItem() + "";
        obs = tf_obs.getText();

        if (validarFormulario()) {
            if (osController.alterarOS(id_os, id_paciente,cod_os, tipo_servico, servico, quantidade, data_entrada, data_entrega,
                    valor_unitario, valor_total, situacao_servico, situacao_pagamento, obs)) {
                JOptionPane.showMessageDialog(this, "OS alterada com sucesso.");
                limparCampos();
                desabilitarCampos();
            } else {
                JOptionPane.showMessageDialog(this, "Problema na gravação.");
            }
        } else {
            JOptionPane.showMessageDialog(this, "Campos com * são obrigatórios.");
        }
    }//GEN-LAST:event_btn_alterarActionPerformed

    private void btn_salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_salvarActionPerformed
        OSController osController = new OSController();
        nome_paciente = cb_paciente.getSelectedItem() + "";//busca o nome da clinica que esta no cb_clinica.
        id_paciente = osController.buscarIDPaciente(nome_paciente);//busca o id_clinica a partir do nome selecionado no cb_clinica.
        tipo_servico = cb_tipo_servico.getSelectedItem() + "";
        servico = cb_servico.getSelectedItem() + "";
        quantidade = Integer.parseInt(cb_quantidade.getSelectedItem() + "");
        data_entrada = inverterData(tf_data_entrada.getText()+"");
        data_entrega = inverterData(tf_data_entrega.getText()+"");
        valor_unitario = tf_valor_unitario.getText();
        valor_total = tf_valor_total.getText();
        situacao_servico = cb_situacao.getSelectedItem() + "";
        situacao_pagamento = cb_pagamento.getSelectedItem() + "";
        obs = tf_obs.getText();
        cod_os = Integer.parseInt(tf_codigo.getText());

        if (validarFormulario()) {
            if (osController.cadastrarOS(id_paciente,cod_os, tipo_servico, servico, quantidade, data_entrada, data_entrega,
                    valor_unitario, valor_total, situacao_servico, situacao_pagamento, obs)) {
                if(cb_pagamento.getSelectedItem().equals("Em aberto")){
                    
                    qtd_parcelas = Integer.parseInt(cb_qtd_parcelas.getSelectedItem()+"");
                    vencimento_parcela = inverterData(tf_vencimento_parcela.getText()+"");
                    valor_parcela = Float.parseFloat(valor_total)/(qtd_parcelas)+"";
                    
                    for(int i=1; i<=qtd_parcelas;i++){
                        ParcelaController parcelaController = new ParcelaController();
                        parcelaController.cadastrarParcelas(cod_os,id_paciente,valor_parcela,i,vencimento_parcela,situacao);
                        parcelaController = null;
                    }
                }
                JOptionPane.showMessageDialog(this, "OS cadastrada com sucesso.");
                limparCampos();
                cb_paciente_consulta.removeAllItems();
                osController.listarOSCombo();
            } else {
                JOptionPane.showMessageDialog(this, "Problema na gravação.");
            }
        } else {
            JOptionPane.showMessageDialog(this, "Campos com * são obrigatórios.");
        }
    }//GEN-LAST:event_btn_salvarActionPerformed

    private void btn_novoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_novoActionPerformed
        habilitarCampos();
        limparCampos();
       // incrementarCodigo();
        btn_salvar.setEnabled(true);
    }//GEN-LAST:event_btn_novoActionPerformed

    
    private void btn_pesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_pesquisarActionPerformed
        btn_salvar.setEnabled(false);
        desabilitarCampos();
        String filtrar_por = cb_filtrar.getSelectedItem() + "";//busca tipo de pesquisa.
        String pesquisar = tf_pesquisar.getText();//busca valor a ser pesquisado.

        limparTabelaOS();//limpa a tabela de dentistas para uma nova pesquisa.

        OSController osController = new OSController();
        osController.buscarOS(filtrar_por, pesquisar);//passa o tipo de pesquisa e o valor a ser pesquisado.
    }//GEN-LAST:event_btn_pesquisarActionPerformed

    private void cb_tipo_servicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_tipo_servicoActionPerformed
        OSController osController = new OSController();
        ComboBox t_servico = (ComboBox) cb_tipo_servico.getSelectedItem();
        cb_servico.removeAllItems();
        //int id = osController.buscarIDTipoServico(t_servico.getId());
        osController.listarServicosCombo(t_servico.getId());
        ComboBox servico = (ComboBox)cb_servico.getSelectedItem();
        tf_valor_unitario.setText(servico.getValor());
        calcularTotal();
    }//GEN-LAST:event_cb_tipo_servicoActionPerformed

    private void cb_quantidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_quantidadeActionPerformed
        calcularTotal();
    }//GEN-LAST:event_cb_quantidadeActionPerformed

    private void cb_servicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_servicoActionPerformed
        //OSController osController = new OSController();
        //osController.buscarValorUnitario();
    }//GEN-LAST:event_cb_servicoActionPerformed

    private void jm_menu_backupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_menu_backupActionPerformed
        Base base = new Base();
        int resp = JOptionPane.showConfirmDialog(null, "Realizar Backup?", "Backup", JOptionPane.YES_NO_OPTION);
        if (resp == JOptionPane.YES_OPTION) {
            base.backup();
        }
    }//GEN-LAST:event_jm_menu_backupActionPerformed

    private void jm_menu_restaurar_backupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_menu_restaurar_backupActionPerformed
        Base base = new Base();
        int resp = JOptionPane.showConfirmDialog(null, "Realizar Backup?", "Backup", JOptionPane.YES_NO_OPTION);
        if (resp == JOptionPane.YES_OPTION) {
            base.restaurarBackup();
        }
    }//GEN-LAST:event_jm_menu_restaurar_backupActionPerformed

    private void jm_menu_sairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_menu_sairActionPerformed
        dispose();
    }//GEN-LAST:event_jm_menu_sairActionPerformed

    private void jm_menu_opcoesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_menu_opcoesActionPerformed

   }//GEN-LAST:event_jm_menu_opcoesActionPerformed

    private void jm_menu_clinicasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_menu_clinicasActionPerformed
        frm_clinicas clinicas = new frm_clinicas(nivel_acesso);
        clinicas.setVisible(true);
        // this.setVisible(false);
    }//GEN-LAST:event_jm_menu_clinicasActionPerformed

    private void jm_menu_dentistasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_menu_dentistasActionPerformed
        frm_dentistas dentistas = new frm_dentistas(nivel_acesso);
        dentistas.setVisible(true);
        //  this.setVisible(false);
    }//GEN-LAST:event_jm_menu_dentistasActionPerformed

    private void jm_menu_pacientesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_menu_pacientesActionPerformed
        frm_pacientes pacientes = new frm_pacientes(nivel_acesso);
        pacientes.setVisible(true);
        // this.setVisible(false);
    }//GEN-LAST:event_jm_menu_pacientesActionPerformed

    private void jm_menu_ordem_de_servicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_menu_ordem_de_servicoActionPerformed
        frm_ordem_de_servico os = new frm_ordem_de_servico(nivel_acesso);
        os.setVisible(true);
        // this.setVisible(false);
    }//GEN-LAST:event_jm_menu_ordem_de_servicoActionPerformed

    private void cb_paciente_consultaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_paciente_consultaActionPerformed
        try
        {
            OSController osController = new OSController();
            ParcelaController parcelaController = new ParcelaController();
            //id_paciente = osController.buscarIDPaciente(cb_paciente_consulta.getSelectedItem()+"");
            //int codigoOS = parcelaController.buscarCodigoOS(id_paciente);
            int codOs = Integer.parseInt(cb_paciente_consulta.getSelectedItem()+"");
            
            parcelaController.buscarParcelas(codOs);
        }
        catch(Exception erro)
        {
            System.out.println("Erro: "+erro);
        }
    }//GEN-LAST:event_cb_paciente_consultaActionPerformed

    private void cb_qtd_parcelasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_qtd_parcelasActionPerformed
        int qtd = Integer.parseInt(cb_qtd_parcelas.getSelectedItem()+"");
        float valorTotal = Float.parseFloat(tf_valor_total.getText());
        String valor = String.valueOf(valorTotal/qtd);
        tf_valor_parcela.setText(valor);
    }//GEN-LAST:event_cb_qtd_parcelasActionPerformed

    public void calcularTotal(){
        int qtd = Integer.parseInt(cb_quantidade.getSelectedItem()+"");
        String val_unit = tf_valor_unitario.getText();
        float val = Float.parseFloat(val_unit);
        tf_valor_total.setText((qtd * val)+"");
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frm_clinicas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frm_clinicas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frm_clinicas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frm_clinicas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new frm_ordem_de_servico(nivel_acesso).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_alterar;
    private javax.swing.JButton btn_editar;
    private javax.swing.JButton btn_excluir;
    private javax.swing.JButton btn_novo;
    private javax.swing.JButton btn_pesquisar;
    private javax.swing.JButton btn_salvar;
    private javax.swing.JComboBox cb_filtrar;
    public static javax.swing.JComboBox cb_paciente;
    public static javax.swing.JComboBox cb_paciente_consulta;
    public static javax.swing.JComboBox cb_pagamento;
    private javax.swing.JComboBox cb_qtd_parcelas;
    public static javax.swing.JComboBox cb_quantidade;
    public static javax.swing.JComboBox cb_servico;
    public static javax.swing.JComboBox cb_situacao;
    public static javax.swing.JComboBox cb_tipo_servico;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JMenuBar jm_menu;
    private javax.swing.JMenu jm_menu_ajuda;
    private javax.swing.JMenuItem jm_menu_backup;
    private javax.swing.JMenuItem jm_menu_clinicas;
    private javax.swing.JMenuItem jm_menu_conteudo_ajuda;
    private javax.swing.JMenuItem jm_menu_dentistas;
    private javax.swing.JMenu jm_menu_gerenciar;
    private javax.swing.JMenu jm_menu_opcoes;
    private javax.swing.JMenuItem jm_menu_ordem_de_servico;
    private javax.swing.JMenuItem jm_menu_pacientes;
    private javax.swing.JMenuItem jm_menu_restaurar_backup;
    private javax.swing.JMenuItem jm_menu_sair;
    private javax.swing.JMenuItem jm_menu_sobre;
    public static javax.swing.JMenuItem jm_menu_usuarios;
    private javax.swing.JPanel jp_dados_da_os;
    private javax.swing.JPanel jp_em_aberto;
    private javax.swing.JPanel jp_menu;
    private javax.swing.JPanel jp_paciente;
    private javax.swing.JPanel jp_pesquisa;
    public static javax.swing.JTable jt_os;
    public static javax.swing.JTable jt_parcelas;
    private javax.swing.JLabel lbl_codigo;
    private javax.swing.JLabel lbl_data_entrada;
    private javax.swing.JLabel lbl_data_entrega;
    private javax.swing.JLabel lbl_dentista;
    private javax.swing.JLabel lbl_dentista1;
    private javax.swing.JLabel lbl_filtrar;
    private javax.swing.JLabel lbl_igual;
    private javax.swing.JLabel lbl_obs;
    private javax.swing.JLabel lbl_pagamento;
    private javax.swing.JLabel lbl_qtd;
    private javax.swing.JLabel lbl_servico;
    private javax.swing.JLabel lbl_situacao_servico;
    private javax.swing.JLabel lbl_tipo_servico;
    private javax.swing.JLabel lbl_valor_total;
    private javax.swing.JLabel lbl_valor_unitario;
    public static javax.swing.JTextField tf_codigo;
    public static javax.swing.JFormattedTextField tf_data_entrada;
    public static javax.swing.JFormattedTextField tf_data_entrega;
    public static javax.swing.JTextArea tf_obs;
    private javax.swing.JTextField tf_pesquisar;
    private javax.swing.JFormattedTextField tf_valor_parcela;
    public static javax.swing.JTextField tf_valor_total;
    public static javax.swing.JTextField tf_valor_unitario;
    private javax.swing.JFormattedTextField tf_vencimento_parcela;
    // End of variables declaration//GEN-END:variables
}
